package org.springframework.aop.framework;

import org.springframework.aop.AdvisedSupport;

/**
 * @author zqc
 * @date 2022/12/16
 */
public class ProxyFactory extends AdvisedSupport {

	public ProxyFactory() {
	}

	//这个工厂里的getProxy有两个实现，jdk和cglib的
	public Object getProxy() {
		//传回去之后，做的事情就和我们之前讲的都一样了
		return createAopProxy().getProxy();
	}

	private AopProxy createAopProxy() {
		//这里就是做判断，是false还是true。返回对应的对象动态代理对象
		if (this.isProxyTargetClass() || this.getTargetSource().getTargetClass().length == 0) {
			return new CglibAopProxy(this);
		}

		return new JdkDynamicAopProxy(this);
	}
}
